package com.kjsdfgk.hjmdsf.app;

import android.content.Context;

import com.jess.arms.base.BaseApplication;
import com.kjsdfgk.hjmdsf.app.entity.HistoryItem;
import com.kjsdfgk.hjmdsf.app.entity.WebPhoto;
import com.lksdkjs.live.R;
import com.tencent.bugly.crashreport.CrashReport;

import org.litepal.LitePal;
import org.litepal.LitePalDB;

import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;

import cn.leancloud.AVLogger;
import cn.leancloud.AVOSCloud;
import me.jessyan.autosize.AutoSizeConfig;

import static com.kjsdfgk.hjmdsf.app.Config.DATA_PATH;

public class App extends BaseApplication {


    @Override
    public void onCreate() {
        super.onCreate();
        appContext = this;

        AVOSCloud.setLogLevel(AVLogger.Level.DEBUG);
        AVOSCloud.initialize(this, "TGWLkr2SGCt1XDHw2Gst2w8a-gzGzoHsz", "9Fgh1t3pGFSzdXrKMm2FyKpk");

        AutoSizeConfig.getInstance().setDesignWidthInDp(432);
        AutoSizeConfig.getInstance().setDesignHeightInDp(768);

        CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(appContext);
        strategy.setCrashHandleCallback(new CrashReport.CrashHandleCallback() {
            public Map<String, String> onCrashHandleStart(int crashType, String errorType, String errorMessage, String errorStack) {
                LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();

                map.put("errorType", errorType);
                map.put("errorMessage", errorMessage);
                map.put("errorStack", errorStack);
                return map;
            }
            @Override
            public byte[] onCrashHandleStart2GetExtraDatas(int crashType, String errorType, String errorMessage, String errorStack) {
                try {

                    return "Extra data.".getBytes("UTF-8");
                } catch (Exception e) {
                    return null;
                }
            }
        });

        CrashReport.initCrashReport(appContext , "4447f56fc9" , true, strategy);

        LitePal.initialize(this);


        if (getResources().getBoolean(R.bool.isTablet)){
            AutoSizeConfig.getInstance().setDesignWidthInDp(720);
            AutoSizeConfig.getInstance().setDesignHeightInDp(960);
        }else {
            AutoSizeConfig.getInstance().setDesignWidthInDp(432);
            AutoSizeConfig.getInstance().setDesignHeightInDp(768);
        }

    }

    public static Context appContext;

    public static Context getAppContext() {
        return appContext;
    }
}
